package service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import dao.MerchantDao;
import pojo.Merchant;
import service.MerchantService;

@Service
@Transactional
public class MerchantServiceImpl implements MerchantService {
	
	@Resource(name="merchantDaoImpl")
	private MerchantDao merchantDao;
	
	/*@Override
	public List<Merchant> getAllWarehouses() {
		return merchantDao.findAll();
	}
*/
	@Override

	public Merchant register(Merchant merchant) {
		return merchantDao.add(merchant);	
	}
	
	public Merchant reRegister(Merchant merchant) {
		return merchantDao.update(merchant);
	}


	@Override
	public String login(Merchant merchant) {
		Merchant mer = null;
		if((mer = merchantDao.findByName(merchant))==null){
			return "name error";
		}
		if(!(mer.getPassword().equals(merchant.getPassword()))){
			System.out.println(mer.getPassword());
			System.out.println(merchant.getPassword());
			return "password error";
		}
		return "success";
	}


	@Override
	public Merchant add(Merchant merchant) {
		return merchantDao.add(merchant);
	}


	@Override
	public Merchant update(Merchant merchant) {
		return merchantDao.update(merchant);
	}

	@Override
	public Merchant findByName(Merchant merchant) {
		return merchantDao.findByName(merchant);
	}
}
